import request from "@/utils/request";

// --- 私聊消息 ---

/**
 * 发送私聊消息
 * @param {object} data 消息内容
 */
export function sendPrivateMessageApi(data) {
  return request({
    url: "/message/private/send",
    method: "post",
    data: data,
  });
}

/**
 * 撤回私聊消息
 * @param {number} id 消息ID
 */
export function recallPrivateMessageApi(id) {
  return request({
    url: `/message/private/recall/${id}`,
    method: "delete",
  });
}

/**
 * 将私聊消息设置为已读
 * @param {number} friendId 好友ID
 */
export function readPrivateMessageApi(friendId) {
  return request({
    url: "/message/private/readed",
    method: "put",
    params: { friendId },
  });
}

/**
 * 获取私聊历史消息
 * @param {object} params
 * @param {number} params.friendId 好友ID
 * @param {number} params.page 页码
 * @param {number} params.size 每页数量
 */
export function getPrivateHistoryMessageApi(params) {
  return request({
    url: "/message/private/history",
    method: "get",
    params: params,
  });
}

/**
 * 获取某个会话中已读消息的最大ID
 * @param {number} friendId 好友ID
 */
export function getMaxReadedIdApi(friendId) {
  return request({
    url: "/message/private/maxReadedId",
    method: "get",
    params: { friendId },
  });
}

// --- 群聊消息 ---

/**
 * 发送群聊消息
 * @param {object} data 消息内容
 */
export function sendGroupMessageApi(data) {
  return request({
    url: "/message/group/send",
    method: "post",
    data: data,
  });
}

/**
 * 撤回群聊消息
 * @param {number} id 消息ID
 */
export function recallGroupMessageApi(id) {
  return request({
    url: `/message/group/recall/${id}`,
    method: "delete",
  });
}

/**
 * 将群聊消息设置为已读
 * @param {number} groupId 群聊ID
 */
export function readGroupMessageApi(groupId) {
  return request({
    url: "/message/group/readed",
    method: "put",
    params: { groupId },
  });
}

/**
 * 获取群聊历史消息
 * @param {object} params
 * @param {number} params.groupId 群聊ID
 * @param {number} params.page 页码
 * @param {number} params.size 每页数量
 */
export function getGroupHistoryMessageApi(params) {
  return request({
    url: "/message/group/history",
    method: "get",
    params: params,
  });
}

/**
 * 获取群聊消息已读用户列表
 * @param {object} params
 * @param {number} params.groupId 群聊ID
 * @param {number} params.messageId 消息ID
 */
export function getGroupMessageReadUsersApi(params) {
  return request({
    url: "/message/group/findReadedUsers",
    method: "get",
    params: params,
  });
}

/**
 * 拉取私聊离线消息
 * @param {number} minId 本地最小消息ID
 */
export function pullPrivateOfflineMessageApi(minId) {
  return request({
    url: "/message/private/pullOfflineMessage",
    method: "get",
    params: { minId },
  });
}

/**
 * 拉取群聊离线消息
 * @param {number} minId 本地最小消息ID
 */
export function pullGroupOfflineMessageApi(minId) {
  return request({
    url: "/message/group/pullOfflineMessage",
    method: "get",
    params: { minId },
  });
}
